package io.renren.common.utils;

import io.renren.modules.udp.entity.R5rmSkillstatusEntity;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author Jackie
 * @version 1.0
 * @date 2020/1/13 16:19
 * @description
 */
public class PublicUtil {
    private static final Map<String, List<Field>> CACHE = new HashMap<String, List<Field>>();


    public static void main(String[] args) {
        /*R5rmSkillstatusEntity r5rmSkillstatusEntity = new R5rmSkillstatusEntity();
        List<Field> fields = getFieldOfClass(r5rmSkillstatusEntity.getClass());
        for (int j = 0, size = fields.size(); j < size; j++) {
            try {
                // 获取属性的名字
                Field each = fields.get(j);
                System.out.println(each.getName());
                each.setAccessible(true);
                //为set方法set值
                String type = String.valueOf(each.getType());
                String name = each.getName();
                if (name.equals("ssId")) {
                    each.set(r5rmSkillstatusEntity,  String.valueOf(UUID.randomUUID()));
                }else if (type.equals("class java.lang.Long")) {
                    each.set(r5rmSkillstatusEntity, Long.parseLong("8"));
                }else{
                    each.set(r5rmSkillstatusEntity, "8");
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        System.out.println(r5rmSkillstatusEntity.getSsId());*/
    }

    public static List<Field> getFieldOfClass(Class<?> clazz) {
        List<Field> fields = CACHE.get(clazz.getName());
        if (fields == null) {
            Field[] fieldArr = clazz.getDeclaredFields();
            fields = new ArrayList<Field>(fieldArr.length);
            for (Field each : fieldArr) {
                each.setAccessible(true);
                fields.add(each);
            }
            CACHE.put(clazz.getName(), fields);
        }
        return fields;
    }
    /**
     * 16进制转10进制获取数值
     * @param s1
     * @param s2
     * @param s3
     * @return
     */
    public static String result(String s1,int s2,String s3){
        String s4 ;
        if (s2 != 0) {
            s4 = new BigDecimal((float)Long.parseLong(s1, 16)/100).setScale(s2, BigDecimal.ROUND_HALF_UP).doubleValue() + s3;
        } else {
            s4 = new BigDecimal((float)Long.parseLong(s1, 16)/100).setScale(s2, BigDecimal.ROUND_HALF_UP).intValue() + s3;
        }
        return s4;
    }
}
